------------------------------------------------------------------------------------------------------------------------------------------------
--[[

]]--
------------------------------------------------------------------------------------------------------------------------------------------------
-- PARAM
    local DEBUFF_REMAIN_TIME = 7
    local DEBUFF_UPDATE_TIME_DELTA = 0.2
------------------------------------------------------------------------------------------------------------------------------------------------

local function OnAttached(inst,target) -- 玩家得到 debuff 的瞬间。 穿越洞穴、重新进存档 也会执行。
    inst.entity:SetParent(target.entity)
    -- inst.Network:SetClassifiedTarget(target)
    inst.Transform:SetPosition(0,0,0)
    inst.player = target
    -----------------------------------------------------
    ---
        inst.time = DEBUFF_REMAIN_TIME
        target.components.hutao_com_inspect_data:Set("hutao_debuff_vanishing_butterfly_moment",DEBUFF_REMAIN_TIME)
    -----------------------------------------------------
    ---
        inst:DoPeriodicTask(DEBUFF_UPDATE_TIME_DELTA,function()
            inst.time = inst.time - DEBUFF_UPDATE_TIME_DELTA
            target.components.hutao_com_inspect_data:Set("hutao_debuff_vanishing_butterfly_moment",inst.time)
            if inst.time <= 0 then
                inst:Remove()
            end
        end)
        inst:ListenForEvent("onremove",function()
            target.components.hutao_com_inspect_data:Set("hutao_debuff_vanishing_butterfly_moment",0)
        end)
    -----------------------------------------------------
    --
        if target.components.combat then
            target.components.combat.externaldamagemultipliers:SetModifier(inst,1.35)
        end
    -----------------------------------------------------
end
local function ExtendDebuff(inst)
    inst.time = DEBUFF_REMAIN_TIME
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddNetwork()
    inst.entity:AddTransform()

    inst:AddTag("CLASSIFIED")



    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("debuff")
    inst.components.debuff:SetAttachedFn(OnAttached)
    inst.components.debuff:SetExtendedFn(ExtendDebuff)


    return inst
end

return Prefab("hutao_debuff_vanishing_butterfly_moment", fn)
